#ifndef REALTIMEEDITOR_H
#define REALTIMEEDITOR_H

#include "CollaborationProtocol.h"
#include <map>
#include <vector>
#include <functional>

class CRealTimeEditor
{
public:
    using ChangeCallback = std::function<void(const CollaborationMessage&)>;
    
    struct EditorState {
        wxString modelContent;
        std::map<wxString, wxString> cursorPositions;
        std::vector<wxString> activeComponents;
    };
    
    CRealTimeEditor();
    
    void SetChangeCallback(ChangeCallback callback) { m_changeCallback = callback; }
    
    void EditComponent(const wxString& developerId, const wxString& componentName, const wxString& newContent);
    void AddComponent(const wxString& developerId, const wxString& componentType, const wxString& initialContent);
    void RemoveComponent(const wxString& developerId, const wxString& componentName);
    
    void BroadcastChange(const CollaborationMessage& change);
    void ApplyRemoteChange(const CollaborationMessage& change);
    void ResolveConflict(const wxString& componentName);
    
    EditorState GetCurrentState() const { return m_currentState; }
    std::vector<wxString> GetEditHistory() const;

private:
    EditorState m_currentState;
    ChangeCallback m_changeCallback;
    std::map<wxString, std::vector<CollaborationMessage>> m_editHistory;
    
    void NotifyChanges(const CollaborationMessage& change);
};

#endif
